package com.nxk.modules.config;


import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Value("${file.fileMapPath}")
    private String fileMapPath;

    /**
     * 自定义过滤器,解决前后端分离跨域问题
     * @return
     */
    @Bean
    public FilterRegistrationBean myFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        //传入自己创建的filter
        filterRegistrationBean.setFilter(new MyFilterConfig());
        //设置拦截路径
        filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
        return filterRegistrationBean;
    }

    /**
     * 路径映射,将所有请求路径携带photo的,转发到访问fileMapPath路径
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //其中OTA表示访问的前缀。"file:D:/OTA/"是文件真实的存储路径
       //registry.addResourceHandler("/photo/**").addResourceLocations("file:/localConf/nginx/www/photos/");
        registry.addResourceHandler("/photo/**").addResourceLocations(fileMapPath);
    }






}
